package com.iepacj.service.impl;

import com.alibaba.fastjson.JSON;
import com.iepacj.service.RabbitmqService;
import com.iepacj.vo.Community;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by iEpac on 16/4/28.
 */
@Service
public class RabbitmqServiceImpl implements RabbitmqService {

    private @Autowired AmqpTemplate amqpTemplate;

    private @Autowired MongoTemplate mongoTemplate;

    @Override
    public void sendMessage(String i) {
        Community commun = new Community();
//        commun.setId(System.currentTimeMillis() + Long.valueOf(i));
        commun.setCreateTime(new Date());
        commun.setStatus(0);
        commun.setCommonName("测试数据-" + i);

        amqpTemplate.convertAndSend("inquiry.key", JSON.toJSONString(commun));

    }

    @Override
    public void saveCommunity(Community community) {
        mongoTemplate.insert(community);
    }


}
